//
//  Book.m
//  奇阅
//
//  Created by 奇阅科技 on 14-10-21.
//  Copyright (c) 2014年 奇阅科技. All rights reserved.
//

#import "Book.h"
#import "LKDBHelper.h"
@implementation Book
+(NSString *)getTableName
{
    return @"Book";
}
+(Book *)getFromDict:(NSDictionary *)dict{
    Book *book = [Book new];
    book.articleid = [dict objectForKey:@"articleid"];
    book.author = [dict objectForKey:@"author"];
    book.title = [dict objectForKey:@"title"];
    book.imagefname = [[dict objectForKey:@"imagefname"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    book.bookAbout = [dict objectForKey:@"description"];
    book.bookCommentNum = [dict objectForKey:@"replynum_count"];
    return book;
}
+(Book *)getFromYiDongDict:(NSDictionary *)dict{
    Book *book = [Book new];
    book.articleid = [NSString stringWithFormat:@"qiyou%@",[dict objectForKey:@"articleid"]];
    book.author = [dict objectForKey:@"author"];
    book.title = [dict objectForKey:@"title"];
    book.imagefname = [[dict objectForKey:@"imagefname"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    book.bookAbout = [dict objectForKey:@"description"];
    book.bookCommentNum = [dict objectForKey:@"replynum_count"];
    return book;
}
+(Book *)getFromSearchDict:(NSDictionary *)dict{
    Book *book = [Book new];
    book.articleid = [dict objectForKey:@"bookid"];
    book.author = [dict objectForKey:@"author"];
    book.title = [dict objectForKey:@"title"];
    book.imagefname = [[dict objectForKey:@"coverpic"]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    book.bookAbout = [dict objectForKey:@"description"];
    book.bookCommentNum = [dict objectForKey:@"replynum_count"];
    return book;
}
///移动基地的搜索解析
+(Book *)getFromYiDongSearchDict:(NSDictionary *)dict{
    /*"BookId": "1178068",
     "BookName": "盘龙",
     "BookCoverLogo": "/r/cover_file/8068/1178068/20110113103220/盘龙90120.jpg",
     "BookAuthor": "我吃西红柿",
     "BookStatus": "完本",
     "BookCategory": "玄幻奇幻",
     "BookBrief": "手握盘龙戒指，少年竟敢闯荡魔幻世界。遨游天际的黑色巨龙，瞬间焚烧江河的魔咒，一切充满惊奇又值得期待。",
     "BookChapterTotalSize": "806",
     "BookUpdateTime": "2009-07-13"*/
    Book *book = [Book new];
    book.articleid = [NSString stringWithFormat:@"qiyou%@",[dict objectForKey:@"BookId"]];
    book.author = [dict objectForKey:@"BookAuthor"];
    book.title = [dict objectForKey:@"BookName"];
    book.imagefname = [[NSString stringWithFormat:@"http://wap.cmread.com%@",[dict objectForKey:@"BookCoverLogo"]]stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    //http://wap.cmread.com/r/cover_file/8068/1178068/20110113103220/盘龙90120.jpg
    book.bookAbout = [dict objectForKey:@"BookBrief"];
    book.bookCommentNum = [dict objectForKey:@"replynum_count"];
    return book;
    
}
///更新 数据
-(void)upDateNew:(Book *)newBook{
    self.imagefname = newBook.imagefname;
    self.bookAbout = newBook.bookAbout;
    self.title = newBook.title;
    self.author = newBook.author;
    self.bookCommentNum = newBook.bookCommentNum;
    [Book updateToDBWithSet:[NSString stringWithFormat:@"imagefname='%@',bookAbout='%@',title='%@',author='%@',bookCommentNum='%@'",self.imagefname,self.bookAbout,self.title,self.author,self.bookCommentNum] where:[NSString stringWithFormat:@"articleid='%@'",self.articleid]];
}

-(void)updateImagefname:(NSString *)imagefname{
    self.imagefname = imagefname;
//    [[ZMYLKDB getLKDBHelper]updateBook:self];
}
@end
